package com.security.exception;

import com.security.utils.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public R customerException(CustomException e){
        return R.error(e);
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R exception(Exception e){
        return R.error(new CustomException(CustomExceptionType.OTHER_ERROR,"未知异常"));
    }

}
